#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<queue>
#include<vector>
//https://www.luogu.com.cn/problem/P1190
using namespace std;

priority_queue<int,vector<int>, greater<int>> heap;
int n, m;


int main()
{
	cin >> n >> m;

	for(int i = 1 ; i <= m ; ++i)
	heap.push(0);

	int ret = 0;
	for (int i = 1; i <= n; ++i)
	{
		int tmp; cin >> tmp;

		int t = heap.top(); heap.pop();
		t += tmp;
		ret = max(t, ret);
		heap.push(t);
	}

	cout << ret << endl;

	return 0;
}